]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Chain up in NotificationPolicy constructor
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 11 Dec 2018 10:17:30 +0000 (11:17 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Tue, 22 Jan 2019 21:33:46 +0000 (21:33 +0000)
We currently deliberately avoid chaining up in derived policy
constructors to not override properties with their defaults.
That's a neat trick that will stop working when porting to ES6
classes, as chaining up is necessary to actually initialize the
object there (including "this").

Address this by turning all properties into (overridable) getters
that are backed by private properties by default.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/350

js/ui/messageTray.js

index 7ce977f47b753cfdbe5ccc93bbd00f9b15d68590..3c98b4f959788c13a7a25f23399afb51eaf34324 100644 (file)
@@ -146,13 +146,40 @@ var NotificationPolicy = new Lang.Class({
                                         showInLockScreen: true,
                                         detailsInLockScreen: false
                                       });
-        Lang.copyProperties(params, this);
+        Object.getOwnPropertyNames(params).forEach(key => {
+            let desc = Object.getOwnPropertyDescriptor(params, key);
+            Object.defineProperty(this, `_${key}`, desc);
+        });
     },
 
     // Do nothing for the default policy. These methods are only useful for the
     // GSettings policy.
     store() { },
-    destroy() { }
+    destroy() { },
+
+    get enable() {
+        return this._enable;
+    },
+
+    get enableSound() {
+        return this._enableSound;
+    },
+
+    get showBanners() {
+        return this._showBanners;
+    },
+
+    get forceExpanded() {
+        return this._forceExpanded;
+    },
+
+    get showInLockScreen() {
+        return this._showInLockScreen;
+    },
+
+    get detailsInLockScreen() {
+        return this._detailsInLockScreen;
+    }
 });
 Signals.addSignalMethods(NotificationPolicy.prototype);
 
@@ -161,8 +188,7 @@ var NotificationGenericPolicy = new Lang.Class({
     Extends: NotificationPolicy,
 
     _init() {
-        // Don't chain to parent, it would try setting
-        // our properties to the defaults
+        this.parent();
 
         this.id = 'generic';
 
@@ -180,28 +206,12 @@ var NotificationGenericPolicy = new Lang.Class({
         this.emit('policy-changed', key);
     },
 
-    get enable() {
-        return true;
-    },
-
-    get enableSound() {
-        return true;
-    },
-
     get showBanners() {
         return this._masterSettings.get_boolean('show-banners');
     },
 
-    get forceExpanded() {
-        return false;
-    },
-
     get showInLockScreen() {
         return this._masterSettings.get_boolean('show-in-lock-screen');
-    },
-
-    get detailsInLockScreen() {
-        return false;
     }
 });
 
@@ -210,8 +220,7 @@ var NotificationApplicationPolicy = new Lang.Class({
     Extends: NotificationPolicy,
 
     _init(id) {
-        // Don't chain to parent, it would try setting
-        // our properties to the defaults
+        this.parent();
 
         this.id = id;
         this._canonicalId = this._canonicalizeId(id);